<?php
$jooRoot = dirname(dirname(dirname(__FILE__)));

if (!empty($_FILES)) {
	$tempFile = $_FILES['Filedata']['tmp_name'];
	$targetPath = $jooRoot . '/images/uploads/';
	
	if(!is_dir($targetPath)) die($targetPath . '目录不存在。');
	
	if(!is_writable($targetPath)) die($targetPath . '目录不可写。');
	
	$fileExt = '.' . end(explode('.', $_FILES['Filedata']['name']));
	
	$randromFileName = substr(md5(microtime(true)), rand(0, 20), 5) . rand(0,9);
	
	$targetFile =  str_replace('\\','/',$targetPath) . $randromFileName . $fileExt;
		
	move_uploaded_file($tempFile,$targetFile);
	
	echo str_replace(str_replace('\\','/',$_SERVER['DOCUMENT_ROOT']),'',$targetFile);
}

if (!empty($_GET['f'])) {
	$file = $_SERVER['DOCUMENT_ROOT'] . $_GET['f'];
	if (is_file($file)) unlink($file);
}